export interface IProduct {
  id: number
  title: string
  price: number
  inventory: number //库存
}

const _product: IProduct[] = [
  { id: 1, title: 'IPad 4 Mini', price: 500, inventory: 2 },
  { id: 2, title: '苹果', price: 10.99, inventory: 10 },
  { id: 3, title: '小米 11', price: 2500.6, inventory: 5 },
]

export const getProducts = async () => {
  await wait(100)
  return _product
}

export const buyProducts = async () => {
  await wait(100)
  return Math.random() > 0.5
}

async function wait(delay: number) {
  return new Promise(resolve => { setTimeout(resolve, delay) })
}